package com.gimi.cloud.bbp.manage.service.userInfo.Impl;


import com.gimi.cloud.bbp.manage.service.userInfo.UserInfoService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.dao.dao.User.UserInfoDao;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gimi.cloud.bbp.dto.userInfo.RdUserInfoDTO;
import com.gimi.cloud.bbp.entity.userInfo.RdUserInfoEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
@Transactional
public class UserInfoServiceImpl implements UserInfoService {
	
	@Autowired
	private UserInfoDao userInfoDao;


	@Override
	public List<RdUserInfoEntity> getUsreInfoList() {
		List<RdUserInfoEntity> list = userInfoDao.selectAll();
		return list;
	}

	@Override
	public PageInfo<RdUserInfoEntity> getUserInfoPageList(RdUserInfoDTO userInfoDTO) {
	    PageHelper.startPage(userInfoDTO.getCurrentPage(), userInfoDTO.getPageSize());
	    List<RdUserInfoEntity> list = userInfoDao.selectAll();
	    PageInfo<RdUserInfoEntity> page = new PageInfo<>(list);
		return page;
	}

	@Override
	public Long getCount() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public RdUserInfoDTO getUserInfoSingle(RdUserInfoDTO userInfoDTO) {
		RdUserInfoEntity userInfoEntity = userInfoDao.selectByUserId(userInfoDTO.getUserId());
		RdUserInfoDTO dto = new RdUserInfoDTO();
		BeanUtils.copyProperties(userInfoEntity, dto);
		return dto;
	}

	@Override
	public void updateUserInfo(RdUserInfoDTO userInfoDTO) {
		RdUserInfoEntity record = new RdUserInfoEntity();
		BeanUtils.copyProperties(userInfoDTO, record);
		int i = userInfoDao.updateByPrimaryKeySelective(record);
		if (i <= 0) {
			throw new MsgException(ResponseCodeEnum.INVALID);
		}
	}

}
